using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Collections;

namespace OpenComposite.EII.Designer
{
	public class DesignerSite :ISite
	{
		#region Initialization
		public DesignerSite(IServiceProvider serviceProvider, IComponent component, IContainer container)
		{
			_designMode = false;
			_name = "";
			_component = component;
			_container = container;
			_svcProvider = serviceProvider;
		}
		public DesignerSite(IServiceProvider serviceProvider, IComponent component, IContainer container,
			bool designMode)
		{
			_designMode = designMode;
			_name = "";
			_component = component;
			_container = container;
			_svcProvider = serviceProvider;
		}
		#endregion

		#region Private Members

		#region Variables
		private bool _designMode;
		private string _name;
		private IComponent _component;
		private IContainer _container;
		private IServiceProvider _svcProvider;
		#endregion

		#endregion

		#region ISite Members

		public IComponent Component
		{
			get { return _component; }
		}

		public IContainer Container
		{
			get { return _container; }
		}

		public bool DesignMode
		{
			get { return _designMode; }
		}

		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
			}
		}

		#endregion

		#region IServiceProvider Members

		public object GetService(Type serviceType)
		{
			IServiceProvider svcProvider = _svcProvider;
			if ( svcProvider == null && _component != null ) {
				if ( _component is IServiceProvider )
					svcProvider = (IServiceProvider)_component;
				else if ( _component.Site != null )
					svcProvider = _component.Site;
			}
			if ( svcProvider == null && _container != null && _container is IServiceProvider )
				svcProvider = (IServiceProvider)_container;

			if ( svcProvider != null )
				return svcProvider.GetService(serviceType);
			else
				return null;
		}

		#endregion
	}
}
